<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="en">
<head>
  <meta charset="UTF-8"/>
<script>
    (function(){
        if(''){
            if (prompt('请输入文章密码') !== ''){
                alert('密码错误');
                history.back();
            }
        }
    })();
</script>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/blog/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/blog/lib/pace/pace-theme-corner-indicator.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />





  <link rel="alternate" href="/blog/" title="DH's Blog" type="application/atom+xml" />






<meta name="description" content="1、Git简介1.1、Git是什么？ Git是一个免费的开源 分布式版本控制系统，旨在快速高效地处理从小型到大型项目的所有内容。 Git 易于学习， 占地面积小，具有闪电般的快速性能。它具有Subversion，CVS，Perforce和ClearCase之类的SCM工具，具有廉价的本地分支，方便的暂存区域和 多个工作流等功能。  1.2、Git有哪些优势？ 官方的讲： 从一般开发者的角度来看，g">
<meta property="og:type" content="article">
<meta property="og:title" content="Git-详细使用">
<meta property="og:url" content="https://dhpro.gitee.io/blog/2020/03/18/Git-%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/index.html">
<meta property="og:site_name" content="DH&#39;s Blog">
<meta property="og:description" content="1、Git简介1.1、Git是什么？ Git是一个免费的开源 分布式版本控制系统，旨在快速高效地处理从小型到大型项目的所有内容。 Git 易于学习， 占地面积小，具有闪电般的快速性能。它具有Subversion，CVS，Perforce和ClearCase之类的SCM工具，具有廉价的本地分支，方便的暂存区域和 多个工作流等功能。  1.2、Git有哪些优势？ 官方的讲： 从一般开发者的角度来看，g">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/content.png">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/vim.png">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/path.png">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/default.png">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/line_end.png">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/terminal.png">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/cache.png">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/xiaoguo.png">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/config.png">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/gitconfig.png">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/status.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/new_file.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_status.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_add.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_status2.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_rm_cache.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_commit1.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_commit2.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_after_commit.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/update_file.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_log.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_log1.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_log2.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_log3.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/reset_hard.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/rm1.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/rm2.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/recover_file.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/diff1.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/diff2.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/show_branch.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/create_branch.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/delete_branch.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/checkout_branck.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/branch_version.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/branch_version2.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/merge.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/merge1.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/merge_err.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/merge_err1.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/merge_err2.jpg">
<meta property="og:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/init_local.jpg">
<meta property="article:published_time" content="2020-03-18T13:25:03.000Z">
<meta property="article:modified_time" content="2020-03-19T10:55:22.229Z">
<meta property="article:author" content="Ding Huang">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/content.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://dhpro.gitee.io/blog/2020/03/18/Git-详细使用/"/>





  <title>Git-详细使用 | DH's Blog</title>
  








<meta name="generator" content="Hexo 4.2.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="en">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">DH's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">It's not a Bug, it's a Feature!</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            About
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            Search
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="Searching..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://dhpro.gitee.io/blog/blog/2020/03/18/Git-%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Ding Huang">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="DH's Blog">
    </span>

    
      <header class="post-header">
		



        
        
          <h1 class="post-title" itemprop="name headline">Git-详细使用</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2020-03-18T21:25:03+08:00">
                2020-03-18
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/Git/" itemprop="url" rel="index">
                    <span itemprop="name">Git</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/blog/2020/03/18/Git-%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/blog/2020/03/18/Git-%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i> 浏览
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">Words count in article&#58;</span>
                
                <span title="Words count in article">
                  2k word
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">Reading time &asymp;</span>
                
                <span title="Reading time">
                  7 minute
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="1、Git简介"><a href="#1、Git简介" class="headerlink" title="1、Git简介"></a>1、Git简介</h2><h4 id="1-1、Git是什么？"><a href="#1-1、Git是什么？" class="headerlink" title="1.1、Git是什么？"></a>1.1、Git是什么？</h4><blockquote>
<p>Git是一个免费的开源 分布式版本控制系统，旨在快速高效地处理从小型到大型项目的所有内容。</p>
<p>Git 易于学习， 占地面积小，具有闪电般的快速性能。它具有Subversion，CVS，Perforce和ClearCase之类的SCM工具，具有廉价的本地分支，方便的暂存区域和 多个工作流等功能。</p>
</blockquote>
<h4 id="1-2、Git有哪些优势？"><a href="#1-2、Git有哪些优势？" class="headerlink" title="1.2、Git有哪些优势？"></a>1.2、Git有哪些优势？</h4><blockquote>
<p>官方的讲：</p>
<p>从一般开发者的角度来看，git有以下功能：</p>
<p>1、从服务器上克隆完整的Git仓库（包括代码和版本信息）到单机上。</p>
<p>2、在自己的机器上根据不同的开发目的，创建分支，修改代码。</p>
<p>3、在单机上自己创建的分支上提交代码。</p>
<p>4、在单机上合并分支。</p>
<p>5、把服务器上最新版的代码fetch下来，然后跟自己的主分支合并。</p>
<p>6、生成补丁（patch），把补丁发送给主开发者。</p>
<p>7、看主开发者的反馈，如果主开发者发现两个一般开发者之间有冲突（他们之间可以合作解决的冲突），就会要求他们先解决冲突，然后再由其中一个人提交。如果主开发者可以自己解决，或者没有冲突，就通过。</p>
<p>8、一般开发者之间解决冲突的方法，开发者之间可以使用pull 命令解决冲突，解决完冲突之后再向主开发者提交补丁。</p>
</blockquote>
<blockquote>
<p>我们自己讲：</p>
<p>​    大部分操作在本地完成，无需联网<br>​    保证了完整性<br>​    尽可能地添加数据，而不是修改或者删除数据<br>​    分支操作非常快捷、流畅<br>​    与Linux命令全面兼容（同一个爹）</p>
</blockquote>
<h2 id="2、安装Git"><a href="#2、安装Git" class="headerlink" title="2、安装Git"></a>2、安装Git</h2><blockquote>
<p>下载地址：<a href="https://git-scm.com/downloads" target="_blank" rel="noopener">Git下载地址</a></p>
</blockquote>
<p>安装目录：</p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/content.png" alt=""></p>
<p>Next：</p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/vim.png" alt=""></p>
<p>注意：</p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/path.png" alt=""></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/default.png" alt=""></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/line_end.png" alt=""></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/terminal.png" alt=""></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/cache.png" alt=""></p>
<h2 id="3、Git结构"><a href="#3、Git结构" class="headerlink" title="3、Git结构"></a>3、Git结构</h2><h4 id="3-1、工作区"><a href="#3-1、工作区" class="headerlink" title="3.1、工作区"></a>3.1、工作区</h4><blockquote>
<p>写代码：我们写代码的地方</p>
</blockquote>
<h4 id="3-2、暂存区"><a href="#3-2、暂存区" class="headerlink" title="3.2、暂存区"></a>3.2、暂存区</h4><blockquote>
<p>临时存储：打算提交的东西，但是暂时还没提交，暂时先存在这儿，后续可以提交到本地库，也可以撤回来</p>
</blockquote>
<h4 id="3-3、本地库"><a href="#3-3、本地库" class="headerlink" title="3.3、本地库"></a>3.3、本地库</h4><blockquote>
<p>历史版本</p>
</blockquote>
<h4 id="3-4、如何使用"><a href="#3-4、如何使用" class="headerlink" title="3.4、如何使用"></a>3.4、如何使用</h4><blockquote>
<p>工作区 —-git add —-暂存区 —-git commit —-本地库</p>
</blockquote>
<h4 id="3-5、Git和托管中心"><a href="#3-5、Git和托管中心" class="headerlink" title="3.5、Git和托管中心"></a>3.5、Git和托管中心</h4><blockquote>
<p>托管中心作用：维护远程库</p>
<p>​    局域网环境下<br>​        GitLab服务器<br>​    外网环境下<br>​        GitHub<br>​        码云</p>
</blockquote>
<h4 id="3-6、本地库和远程库"><a href="#3-6、本地库和远程库" class="headerlink" title="3.6、本地库和远程库"></a>3.6、本地库和远程库</h4><blockquote>
<p>团队内部协作<br>跨团队协作</p>
</blockquote>
<h2 id="4、Git命令行操作"><a href="#4、Git命令行操作" class="headerlink" title="4、Git命令行操作"></a>4、Git命令行操作</h2><h4 id="4-1、本地库操作"><a href="#4-1、本地库操作" class="headerlink" title="4.1、本地库操作"></a>4.1、本地库操作</h4><h5 id="4-1-1、本地库初始化"><a href="#4-1-1、本地库初始化" class="headerlink" title="4.1.1、本地库初始化"></a>4.1.1、本地库初始化</h5><p><strong>创建项目：</strong></p>
<div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">mkdir 项目名</span></span><br><span class="line">mkdir WeChat</span><br></pre></td></tr></table></figure></div>

<p><strong>命令：</strong></p>
<div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git init</span><br></pre></td></tr></table></figure></div>

<p><strong>效果：</strong></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/xiaoguo.png" alt=""></p>
<p><strong>注意：</strong></p>
<blockquote>
<p>.git目录中存放的是本地库相关的子目录和文件，不要删除 ，也不要胡乱修改</p>
</blockquote>
<h6 id="4-1-1-1、设置签名"><a href="#4-1-1-1、设置签名" class="headerlink" title="4.1.1.1、设置签名"></a>4.1.1.1、设置签名</h6><ul>
<li><p>签名形式：</p>
<ul>
<li>用户名：Tom</li>
<li>Email地址：<a href="mailto:kjljd@dh.com">kjljd@dh.com</a> （ 用户名和邮箱不用一致，邮箱错误也可以，不会发邮 件，仅仅是一个身份的代表，相当于id）</li>
</ul>
</li>
<li><p>签名作用：</p>
<ul>
<li>区分开发人员的身份</li>
</ul>
</li>
<li><p>辨析：</p>
<ul>
<li>这里的 签名用户名和Email、 和 登录远程库（代码托管中心）的账号和密码没有关系</li>
</ul>
</li>
</ul>
<blockquote>
<p>设置签名命令：</p>
<ul>
<li>项目级别/仓库级别：仅在当前本地库范围有效</li>
</ul>
<div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">git config 用户名  密码</span></span><br><span class="line">git config user.name tom_pro</span><br><span class="line">git config user.email goodMoring_pro@163.com</span><br></pre></td></tr></table></figure></div>

<div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat .git/config	--&gt; 项目级别的信息保存目录</span><br></pre></td></tr></table></figure></div>

<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/config.png" alt=""></p>
<ul>
<li>系统用户级别：登录当前操作系统的用户范围</li>
</ul>
<div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">git config --global 用户名  密码</span></span><br><span class="line">git config --global user.name tom_glo</span><br><span class="line">git config --global user.email goodMoring_glo@163.com</span><br></pre></td></tr></table></figure></div>

<div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd ~</span><br><span class="line">cat .gitconfig --&gt; 系统级别的信息保存目录</span><br></pre></td></tr></table></figure></div>

<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/gitconfig.png" alt=""></p>
<ul>
<li><p>优先级：</p>
<ul>
<li><p>就近原则，项目级别优先于系统用户级别，二者都有时采用项目级别 </p>
<p>的签名 。</p>
</li>
<li><p>如果只有系统用户级别的签名，就以系统用户级别的签名为准。</p>
</li>
<li><p>二者都没有不允许。</p>
</li>
</ul>
</li>
</ul>
</blockquote>
<h5 id="4-1-2、全局相关设置"><a href="#4-1-2、全局相关设置" class="headerlink" title="4.1.2、全局相关设置"></a>4.1.2、全局相关设置</h5><h6 id="4-1-2-1、查看全局配置"><a href="#4-1-2-1、查看全局配置" class="headerlink" title="4.1.2.1、查看全局配置"></a>4.1.2.1、查看全局配置</h6><div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --list</span><br></pre></td></tr></table></figure></div>

<h6 id="4-1-2-2、设置全局签名"><a href="#4-1-2-2、设置全局签名" class="headerlink" title="4.1.2.2、设置全局签名"></a>4.1.2.2、设置全局签名</h6><div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.name "输入你的用户名"</span><br><span class="line">git config --global user.email "输入你的邮箱"</span><br></pre></td></tr></table></figure></div>

<p>4.1.2.3、修改全局配置</p>
<div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global --replace-all user.name "输入你的用户名"</span><br><span class="line">git config --global --replace-all user.email "输入你的邮箱"</span><br></pre></td></tr></table></figure></div>

<h5 id="4-1-3、基本操作"><a href="#4-1-3、基本操作" class="headerlink" title="4.1.3、基本操作"></a>4.1.3、基本操作</h5><h6 id="4-1-3-1、查看状态"><a href="#4-1-3-1、查看状态" class="headerlink" title="4.1.3.1、查看状态"></a>4.1.3.1、查看状态</h6><div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">查看工作区、暂存区状态</span></span><br><span class="line">git status</span><br></pre></td></tr></table></figure></div>

<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/status.jpg" alt=""></p>
<h6 id="4-1-3-2、创建文件"><a href="#4-1-3-2、创建文件" class="headerlink" title="4.1.3.2、创建文件"></a>4.1.3.2、创建文件</h6><div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">vim [File Name]</span></span><br><span class="line">vim good.txt</span><br></pre></td></tr></table></figure></div>

<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/new_file.jpg" alt=""></p>
<p><strong>创建文件后查看状态：</strong></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_status.jpg" alt=""></p>
<h6 id="4-1-3-3、工作区添加到暂存区"><a href="#4-1-3-3、工作区添加到暂存区" class="headerlink" title="4.1.3.3、工作区添加到暂存区"></a>4.1.3.3、工作区添加到暂存区</h6><div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">git add [File Name]</span></span><br><span class="line">git add good.txt</span><br></pre></td></tr></table></figure></div>

<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_add.jpg" alt=""></p>
<p><strong>添加后查看状态：</strong></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_status2.jpg" alt=""></p>
<h6 id="4-1-3-4、从缓存区撤回"><a href="#4-1-3-4、从缓存区撤回" class="headerlink" title="4.1.3.4、从缓存区撤回"></a>4.1.3.4、从缓存区撤回</h6><div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">git rm --cached [File Name]</span></span><br><span class="line">git rm --cached good.txt</span><br></pre></td></tr></table></figure></div>

<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_rm_cache.jpg" alt=""></p>
<h6 id="4-1-3-5、暂存区提交到本地库"><a href="#4-1-3-5、暂存区提交到本地库" class="headerlink" title="4.1.3.5、暂存区提交到本地库"></a>4.1.3.5、暂存区提交到本地库</h6><div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">第一种提交：git commit [File Name]</span></span><br><span class="line">git commit good.txt</span><br><span class="line"><span class="meta">#</span><span class="bash">常用提交：git commit -m <span class="string">"[commit message]"</span> [File Name]</span></span><br><span class="line">git commit -m "My second commit,modify good.txt" good.txt</span><br></pre></td></tr></table></figure></div>

<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_commit1.jpg" alt=""></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_commit2.jpg" alt=""></p>
<p><strong>提交之后查看：</strong></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_after_commit.jpg" alt=""></p>
<h6 id="4-1-3-6、修改文件后情况"><a href="#4-1-3-6、修改文件后情况" class="headerlink" title="4.1.3.6、修改文件后情况"></a>4.1.3.6、修改文件后情况</h6><p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/update_file.jpg" alt=""></p>
<p><strong>添加到暂存区：</strong></p>
<div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git add [fileName]</span><br></pre></td></tr></table></figure></div>

<p><strong>提交到本地库：</strong></p>
<div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git commit -m "desc" [fileName]</span><br></pre></td></tr></table></figure></div>

<h6 id="4-1-3-7、查看历史记录【版本】控制"><a href="#4-1-3-7、查看历史记录【版本】控制" class="headerlink" title="4.1.3.7、查看历史记录【版本】控制"></a>4.1.3.7、查看历史记录【版本】控制</h6><p><strong>历史记录直观感受：</strong></p>
<div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git log</span><br></pre></td></tr></table></figure></div>

<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_log.jpg" alt=""></p>
<p>如果日志信息【版本】很多，会导致一屏放不下，使用下面的命令，会变得好一点</p>
<div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git log --pretty=oneline</span><br><span class="line">git log --oneline  --&gt; 只显示历史版本</span><br><span class="line">git reflog  --&gt; 显示所有版本</span><br></pre></td></tr></table></figure></div>

<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_log1.jpg" alt=""></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_log2.jpg" alt=""></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/git_log3.jpg" alt=""></p>
<h6 id="4-1-3-8、前进后退历史记录"><a href="#4-1-3-8、前进后退历史记录" class="headerlink" title="4.1.3.8、前进后退历史记录"></a>4.1.3.8、前进后退历史记录</h6><p>4.1.3.8.1、基于索引值操作【推荐】</p>
<div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">git reset --hard [索引]</span></span><br><span class="line">git reset --hard 51d4ed9</span><br></pre></td></tr></table></figure></div>

<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/reset_hard.jpg" alt=""></p>
<p>4.1.3.8.2、使用^符号</p>
<blockquote>
<p>只能往后，不能往前，一个^符号，表示退一步</p>
</blockquote>
<div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">git reset --hard HEAD^</span><br><span class="line">git reset --hard HEAD^^</span><br><span class="line">git reset --hard HEAD^^^</span><br><span class="line">……</span><br><span class="line">git reset --hard HEAD^^^^…………^^</span><br></pre></td></tr></table></figure></div>

<p>4.1.3.8.3、使用~符号</p>
<div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git reset --hard HEAD~3</span><br><span class="line">git reset --hard HEAD~10 --&gt; 相当于10个^符号</span><br></pre></td></tr></table></figure></div>

<p>4.1.3.8.4、hard和soft和mixed参数对比</p>
<ul>
<li>soft<ul>
<li>仅仅在本地库移动HEAD指针</li>
</ul>
</li>
<li>mixed<ul>
<li>在本地库移动指针</li>
</ul>
</li>
<li>重置缓存区</li>
<li>hard<ul>
<li>本地库移动指针</li>
</ul>
</li>
<li>重置缓存区<ul>
<li>重置工作区</li>
</ul>
</li>
</ul>
<h6 id="4-1-2-9、永久删除文件并找回"><a href="#4-1-2-9、永久删除文件并找回" class="headerlink" title="4.1.2.9、永久删除文件并找回"></a>4.1.2.9、永久删除文件并找回</h6><div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">rm [File Name]</span><br><span class="line">rm aaa.txt</span><br></pre></td></tr></table></figure></div>

<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/rm1.jpg" alt=""></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/rm2.jpg" alt=""></p>
<p><strong>版本回退，找回文件</strong></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/recover_file.jpg" alt=""></p>
<h6 id="4-1-2-10、文件比较"><a href="#4-1-2-10、文件比较" class="headerlink" title="4.1.2.10、文件比较"></a>4.1.2.10、文件比较</h6><div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">git diff [File Name]  --&gt; 将工作区的文件和暂存区的对应文件进行比较 </span></span><br><span class="line">git diff apple.txt</span><br><span class="line"><span class="meta">#</span><span class="bash">git diff [本地库历史版本] [File Name] --&gt; 将工作区的文件和本地库历史记录进行比较  </span></span><br><span class="line"><span class="meta">$</span><span class="bash"> git diff HEAD^ apple.txt</span></span><br></pre></td></tr></table></figure></div>

<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/diff1.jpg" alt=""></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/diff2.jpg" alt=""></p>
<h5 id="4-1-4、分支管理"><a href="#4-1-4、分支管理" class="headerlink" title="4.1.4、分支管理"></a>4.1.4、分支管理</h5><h6 id="4-1-4-1、查看所有分支"><a href="#4-1-4-1、查看所有分支" class="headerlink" title="4.1.4.1、查看所有分支"></a>4.1.4.1、查看所有分支</h6><div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git branch -v</span><br></pre></td></tr></table></figure></div>

<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/show_branch.jpg" alt=""></p>
<h6 id="4-1-4-2、创建分支"><a href="#4-1-4-2、创建分支" class="headerlink" title="4.1.4.2、创建分支"></a>4.1.4.2、创建分支</h6><div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">git branch [分支]</span></span><br><span class="line">git branch hot_fix</span><br></pre></td></tr></table></figure></div>

<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/create_branch.jpg" alt=""></p>
<h6 id="4-1-4-3、删除分支"><a href="#4-1-4-3、删除分支" class="headerlink" title="4.1.4.3、删除分支"></a>4.1.4.3、删除分支</h6><div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">git branch -D [分支名]</span></span><br><span class="line">git branch -D asd</span><br></pre></td></tr></table></figure></div>

<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/delete_branch.jpg" alt=""></p>
<h6 id="4-1-4-4、切换分支"><a href="#4-1-4-4、切换分支" class="headerlink" title="4.1.4.4、切换分支"></a>4.1.4.4、切换分支</h6><div class="highlight-wrap"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SHELL"><figure class="iseeu highlight /shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">git checkout [分支]</span></span><br><span class="line">git checkout hot_fix</span><br></pre></td></tr></table></figure></div>

<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/checkout_branck.jpg" alt=""></p>
<h6 id="4-1-4-5、合并分支"><a href="#4-1-4-5、合并分支" class="headerlink" title="4.1.4.5、合并分支"></a>4.1.4.5、合并分支</h6><p><strong>合并之前：两条分支的版本都是一样的</strong></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/branch_version.jpg" alt=""></p>
<p><strong>现在，在hot_fix分支上模拟“修改，调试Debug完成后”，并且Add、commit到本地库之后，两条分支版本不同了。</strong></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/branch_version2.jpg" alt=""></p>
<p><strong>现在就需要合并到一起，让主分支的版本也向前推进到Debug之后的版本。</strong></p>
<p><strong>合并分支：</strong></p>
<ul>
<li><p>第一步：切换到接受修改的分支（被合并，增加新内容）上</p>
</li>
<li><p>第二步：执行merge命令</p>
<ul>
<li><pre><code class="shell"><span class="meta">#</span><span class="bash">git merge [与那个分支合并:分支名]</span>
git merge hot_fix</code></pre>
</li>
</ul>
</li>
</ul>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/merge.jpg" alt=""></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/merge1.jpg" alt=""></p>
<h6 id="4-1-4-6、解决冲突"><a href="#4-1-4-6、解决冲突" class="headerlink" title="4.1.4.6、解决冲突"></a>4.1.4.6、解决冲突</h6><blockquote>
<p>场景：有可能某一个文件，在两条分支上，都做了修改，（也是在同一个位置修改），合并会产生冲突。</p>
</blockquote>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/merge_err.jpg" alt=""></p>
<blockquote>
<p>解决：</p>
<ul>
<li><p>第一步：编辑文件，删除特殊符号</p>
</li>
<li><p>第二步：把文件修改到满意程度，保存退出</p>
</li>
<li><p>第三步：git add [文件名]</p>
</li>
<li><p>第四步：git commit -m “日志信息”</p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/merge_err1.jpg" alt=""></p>
<p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/merge_err2.jpg" alt=""></p>
</li>
</ul>
</blockquote>
<h3 id="4-2、远程库操作"><a href="#4-2、远程库操作" class="headerlink" title="4.2、远程库操作"></a>4.2、远程库操作</h3><h4 id="4-2-1、初始化本地库"><a href="#4-2-1、初始化本地库" class="headerlink" title="4.2.1、初始化本地库"></a>4.2.1、初始化本地库</h4><p><img src="https://dhpro.gitee.io/blogsource/Git%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/init_local.jpg" alt=""></p>
<h4 id="4-2-2、创建远程库"><a href="#4-2-2、创建远程库" class="headerlink" title="4.2.2、创建远程库"></a>4.2.2、创建远程库</h4><blockquote>
<p>登录GitHub，注意：创建远程库的名字，的时候，可以和本地库名字不同，这里方便演示，起名一致</p>
</blockquote>
<p>未完待续。。。</p>

      
    </div>
    
    
    
	
	<div>
      
        
<div class="my_post_copyright">
  <script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>
  
  <!-- JS库 sweetalert 可修改路径 -->
  <script src="https://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script>
  <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
  <p><span>本文标题:</span><a href="/blog/2020/03/18/Git-%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/">Git-详细使用</a></p>
  <p><span>文章作者:</span><a href="/" title="访问 Ding Huang 的个人博客">Ding Huang</a></p>
  <p><span>发布时间:</span>2020年03月18日 - 21:03</p>
  <p><span>最后更新:</span>2020年03月19日 - 18:03</p>
  <p><span>原始链接:</span><a href="/blog/2020/03/18/Git-%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/" title="Git-详细使用">https://dhpro.gitee.io/blog/2020/03/18/Git-%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/</a>
    <span class="copy-path"  title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="https://dhpro.gitee.io/blog/2020/03/18/Git-%E8%AF%A6%E7%BB%86%E4%BD%BF%E7%94%A8/"  aria-label="复制成功！"></i></span>
  </p>
  <p><span>许可协议:</span><i class="fa fa-creative-commons"></i> 转载请保留原文链接及作者。</p>  
</div>
<script> 
    var clipboard = new Clipboard('.fa-clipboard');
    $(".fa-clipboard").click(function(){
      clipboard.on('success', function(){
        swal({   
          title: "",   
          text: '复制成功',
          icon: "success", 
          showConfirmButton: true
          });
    });
    });  
</script>



      
	</div>

    

    

    

    <footer class="post-footer">
      

      
      
      

      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/blog/images/avatar.jpg"
                alt="Ding Huang" />
            
              <p class="site-author-name" itemprop="name">Ding Huang</p>
              <p class="site-description motion-element" itemprop="description">welcome your coming！</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/%7C%7C%20archive">
              
                  <span class="site-state-item-count">1</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">1</span>
                  <span class="site-state-item-name">categories</span>
                </a>
              </div>
            

            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/blog/" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/itdh" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://gitee.com/dhpro" target="_blank" title="Gitee">
                      
                        <i class="fa fa-fw fa-git-square"></i>Gitee</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://me.csdn.net/qq_45358679" target="_blank" title="CSDN">
                      
                        <i class="fa fa-fw fa-book"></i>CSDN</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://dhpro.gitee.io/blogsource/qqqcode.png" target="_blank" title="QQ">
                      
                        <i class="fa fa-fw fa-qq"></i>QQ</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1、Git简介"><span class="nav-text">1、Git简介</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-1、Git是什么？"><span class="nav-text">1.1、Git是什么？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#1-2、Git有哪些优势？"><span class="nav-text">1.2、Git有哪些优势？</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、安装Git"><span class="nav-text">2、安装Git</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、Git结构"><span class="nav-text">3、Git结构</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#3-1、工作区"><span class="nav-text">3.1、工作区</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-2、暂存区"><span class="nav-text">3.2、暂存区</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-3、本地库"><span class="nav-text">3.3、本地库</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-4、如何使用"><span class="nav-text">3.4、如何使用</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-5、Git和托管中心"><span class="nav-text">3.5、Git和托管中心</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-6、本地库和远程库"><span class="nav-text">3.6、本地库和远程库</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4、Git命令行操作"><span class="nav-text">4、Git命令行操作</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#4-1、本地库操作"><span class="nav-text">4.1、本地库操作</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#4-1-1、本地库初始化"><span class="nav-text">4.1.1、本地库初始化</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-1-1、设置签名"><span class="nav-text">4.1.1.1、设置签名</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#4-1-2、全局相关设置"><span class="nav-text">4.1.2、全局相关设置</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-2-1、查看全局配置"><span class="nav-text">4.1.2.1、查看全局配置</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-2-2、设置全局签名"><span class="nav-text">4.1.2.2、设置全局签名</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#4-1-3、基本操作"><span class="nav-text">4.1.3、基本操作</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-3-1、查看状态"><span class="nav-text">4.1.3.1、查看状态</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-3-2、创建文件"><span class="nav-text">4.1.3.2、创建文件</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-3-3、工作区添加到暂存区"><span class="nav-text">4.1.3.3、工作区添加到暂存区</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-3-4、从缓存区撤回"><span class="nav-text">4.1.3.4、从缓存区撤回</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-3-5、暂存区提交到本地库"><span class="nav-text">4.1.3.5、暂存区提交到本地库</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-3-6、修改文件后情况"><span class="nav-text">4.1.3.6、修改文件后情况</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-3-7、查看历史记录【版本】控制"><span class="nav-text">4.1.3.7、查看历史记录【版本】控制</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-3-8、前进后退历史记录"><span class="nav-text">4.1.3.8、前进后退历史记录</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-2-9、永久删除文件并找回"><span class="nav-text">4.1.2.9、永久删除文件并找回</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-2-10、文件比较"><span class="nav-text">4.1.2.10、文件比较</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#4-1-4、分支管理"><span class="nav-text">4.1.4、分支管理</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-4-1、查看所有分支"><span class="nav-text">4.1.4.1、查看所有分支</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-4-2、创建分支"><span class="nav-text">4.1.4.2、创建分支</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-4-3、删除分支"><span class="nav-text">4.1.4.3、删除分支</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-4-4、切换分支"><span class="nav-text">4.1.4.4、切换分支</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-4-5、合并分支"><span class="nav-text">4.1.4.5、合并分支</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#4-1-4-6、解决冲突"><span class="nav-text">4.1.4.6、解决冲突</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2、远程库操作"><span class="nav-text">4.2、远程库操作</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#4-2-1、初始化本地库"><span class="nav-text">4.2.1、初始化本地库</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-2-2、创建远程库"><span class="nav-text">4.2.2、创建远程库</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Ding Huang</span>

  
</div>

<!--

  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>

-->




<!--
	<div class="powered-by">
	  <i class="fa fa-user-md"></i>
	  <span id="busuanzi_container_site_pv">
		本站访问量:<span id="busuanzi_value_site_pv"></span>次
	  </span>
	  <span class="post-meta-divider">|</span>
	  <span id="busuanzi_container_site_uv">
		本站总访客量：<span id="busuanzi_value_site_uv"></span>人
	  </span>
	</div>

<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共2k字</span>
</div>
-->


        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i> 访问人数
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i> 访问总量
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: true,
        appId: '2WWkPTIgJIRAuFkUHnbjKJlD-gzGzoHsz',
        appKey: 'YIsTAeHLmsJ0dfw2NaGazROv',
        placeholder: 'Just go go',
        avatar:'monsterid',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/blog/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

  
  <a href="https://github.com/itdh" target="_blank" rel="noopener" class="github-corner" aria-label="View source on GitHub">
	<svg width="80" height="80" viewBox="0 0 250 250" style="fill:#70B7FD; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true">
		<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
		<path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
		<path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path>
	</svg>
  </a>
  <style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
  
  <!-- 动态背景 -->
<script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>

<!-- 页面点击小红心 -->
<script type="text/javascript" src="/blog/js/src/clicklove.js"></script>


</body>
</html>


